package com.example.projecth.medicalcheckup;

import com.example.projecth.R;

import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.ActionBar.TabListener;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.Window;



public class MainActivity extends Activity {
	
	public static MediaPlayer[] mp;
	
	private Fragment[] fragments;
		
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mc_maincontainer);
		
		mp = new MediaPlayer[5];
		
		mp[0] = MediaPlayer.create(this, R.raw.bmi);
		mp[0].setLooping(true);		
		
		mp[1] = MediaPlayer.create(this, R.raw.body);
		mp[1].setLooping(true);
		
		mp[3] = MediaPlayer.create(this, R.raw.ovation);
		mp[4] = MediaPlayer.create(this, R.raw.scream);
			
		
		fragments = new Fragment[2];
		fragments[0] = new BMI_Fragment();
		fragments[1] = new BodyAge_Fragment();		
				
		ActionBar bar = getActionBar();
		
		bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
		
		bar.addTab(bar.newTab().setText("비만도 검사").setTabListener(listener));
		bar.addTab(bar.newTab().setText("신체나이 검사").setTabListener(listener));
		
	}

	@Override
	protected void onDestroy() {
		mp[0].release();
		mp[1].release();
		mp[3].release();
		mp[4].release();
		
		super.onDestroy();
	}
	
	private TabListener listener = new TabListener() {
		
		@Override
		public void onTabUnselected(Tab tab, FragmentTransaction ft) {
					
		}		
		@Override
		public void onTabSelected(Tab tab, FragmentTransaction ft) {
			ft.replace(R.id.fragment_container, fragments[tab.getPosition()]);			
		}		
		@Override
		public void onTabReselected(Tab tab, FragmentTransaction ft) {
					
		}
	};		
	
}

